package com.sauro.util;

import com.sauro.common.util.StringUtils;

/**
 * @author dailimin
 * @version 2017年7月20日 下午20:37:02
 */
public class Assert {

    /**
     *
     */
    public static void authc(Boolean isauthc, AbstractCodeUtil code) {
        if (!isauthc) {
            throw new IllegalParameterException(code);
        }
    }

    /**
     *
     */
    public static void isTrue(Boolean object, AbstractCodeUtil code, Object... args) {
        if (!object) {
            throw new IllegalParameterException(code, args);
        }
    }

    /**
     * 参数空(code_IS_NULL)
     */
    public static void isHttpResultTrue(Boolean obj, String paramName) {
        if (!obj) {
            throw new IllegalParameterException(BaseCodeUtil.HTTP_REQUEST_NO_TRUE, paramName);
        }
    }

    /**
     *
     */
    public static void isNull(Object object, String println) {
        if (object != null) {
//            throw new IllegalParameterException(code);
            System.out.println(println);
        }
    }

    public static void isNotNull(Object object, AbstractCodeUtil code) {
        if (object == null) {
            throw new IllegalParameterException(code);
        }
    }

    /**
     * 非空字符串(key_IS_NULL)
     */
    public static void isNotBlank(String text, AbstractCodeUtil code) {
        if (StringUtils.isBlank(text)) {
            throw new IllegalParameterException(code);
        }
    }

    /**
     * 非空字符串(key_IS_NULL)
     */
    public static void isBlank(String text, AbstractCodeUtil code) {
        if (StringUtils.isNotBlank(text)) {
            throw new IllegalParameterException(code);
        }
    }

    /**
     * 参数空(code_IS_NULL)
     */
    public static void paramIsNotBlank(String text, String paramName) {
        if (StringUtils.isBlank(text)) {
            throw new IllegalParameterException(BaseCodeUtil.PARAMETER_NULL, paramName);
        }
    }

    /**
     * 参数空(code_IS_NULL)
     */
    public static void paramIsNotNull(Object obj, String paramName) {
        if (obj == null) {
            throw new IllegalParameterException(BaseCodeUtil.PARAMETER_NULL, paramName);
        }
    }

}
